package cn.fuck;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class TestMap {
    public static void main(String[] args) {
        Map<Integer, LocalDate> dateTreeMap = new TreeMap<>();
        dateTreeMap.put(1997, LocalDate.of(1997, 7, 7));
        dateTreeMap.put(1998, LocalDate.of(1998, 8, 8));
        dateTreeMap.put(1996, LocalDate.of(1996, 6, 6));

//        System.out.println(dateTreeMap);
        Map<String, Person> dateHashMap = new HashMap<>();
        dateHashMap.put("M1-1", new Person(0.0));
        dateHashMap.put("B1-1", new Person(5.5));
        dateHashMap.put("F1-1", new Person(9.9));

//        System.out.println(dateHashMap);
        dateHashMap.getOrDefault("M1-1", new Person(0.0));
        // 迭代最简单的方法
        dateHashMap.forEach((k, v) ->
                System.out.println("k: " + k + " v: " + v));
        Person merge = dateHashMap.merge("P1-1", new Person(-1.0), TestMap::sum);
    }

    private static Person sum(Person a, Person b) {
        return new Person(a.getExp() + b.getExp());
    }
}
